package com.baosight.sczx.zm.cs.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiBlockMeta;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ef.ui.tree.TreeConstants;
import com.baosight.iplat4j.ef.ui.tree.TreeService;
import com.baosight.iplat4j.ep.QueryMap;

/**
 * 工程设置 树
 * <p>Title: ServiceZMCS80.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author zk
 * @version 1.0
 * <pre>Histroy:
 *          2011-9-1 上午06:49:19  zk  Create
 *</pre>
 */
public class ServiceZMCSF0 extends TreeService {
	
	/**
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return label: ServiceZMCS92</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-15上午11:14:45 zk
	 * </p>
	 */
	@SuppressWarnings("rawtypes")
	@Override
	public EiInfo query(EiInfo inInfo) {
		QueryMap queryInfo = QueryMap.getQueryMap(inInfo);
		String p = (String) queryInfo.get(TreeConstants.TREE_NODE);
		List children = new ArrayList();
		if (p == null) {
			p = "$";
		}
		if ("$".equals(p)) {
			children = this.getTopNodes();
		} else {
			children = this.getChildNode(queryInfo);
		}

		EiInfo outInfo = new EiInfo();
		EiBlock block = outInfo.addBlock(p);
		block.setBlockMeta(initMetaData());
		block.setRows(children);
		return outInfo;
	}
	
	/**获取子节点
	 * <p>Function: getChildNode</p>
	 * <p>Description: </p>
	 * <p>return label: ServiceZMCS92</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-15上午11:14:45 zk
	 * </p>
	 *
	 */
	public List<Map<String, String>> getChildNode(QueryMap queryInfo) {
		String parentTypes = getTypeByNode((String)queryInfo.get(TreeConstants.TREE_NODE));//大类0采煤 1掘进 2通防 3其他
		List<Map<String, String>> list = new ArrayList<Map<String, String>>();
		if("0".equals(parentTypes)) 	 list = this.CMList();//采煤
		else if("1".equals(parentTypes)) list = this.JJList(); //掘进
		else if("2".equals(parentTypes)) list = this.TFList(); //通防
		else 							 list = this.QTList();//其他
		return list;
	}
	
	/**
	 * <p>Function: getChildNodes</p>
	 * <p>Description: </p>
	 * <p>return label: ServiceZMCS92</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-15上午11:14:45 zk
	 * </p>
	 *
	 */
	@SuppressWarnings({ "rawtypes" })
	@Override
	public List getChildNodes(String arg0) {
		return null;
	}

	/**
	 * 系统模块树结构：得到根节点数据
	 * <p>Function: getTopNodes</p>
	 * <p>Description: </p>
	 * <p>return label: ServiceZMCS01</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-1-11上午10:11:05 zk
	 * </p>
	 *
	 */

	@Override
	public List<Map<String, String>> getTopNodes() {
		List<Map<String, String>> _topNodes = new ArrayList<Map<String, String>>();

		Map<String, String> _tempMap = new HashMap<String, String>();
		_tempMap.put("label", "CM");
		_tempMap.put("text", "采煤");
		_tempMap.put("parentTypes", "0");
		_tempMap.put("childTypes", "0");
		_tempMap.put("leaf", "0");
		_topNodes.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", "JJ");
		_tempMap.put("text", "掘进");
		_tempMap.put("parentTypes", "1");
		_tempMap.put("childTypes", "0");
		_tempMap.put("leaf", "0");
		_topNodes.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", "TF");
		_tempMap.put("text", "通防");
		_tempMap.put("parentTypes", "2");
		_tempMap.put("childTypes", "0");
		_tempMap.put("leaf", "0");
		_topNodes.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", "QT");
		_tempMap.put("text", "其他");
		_tempMap.put("parentTypes", "3");
		_tempMap.put("childTypes", "0");
		_tempMap.put("leaf", "0");
		_topNodes.add(_tempMap);
		
		return _topNodes;
	}
	
	/**
	 * 采煤的二级分类
	 * <p>Function: CMList</p>
	 * <p>Description: </p>
	 * <p>return label:List<Map<String,String>></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-9-1上午08:15:23 zk
	 * </p>
	 *
	 */
	private List<Map<String, String>> CMList() {
		List<Map<String, String>> _list = new ArrayList<Map<String, String>>();
		
		Map<String, String> _tempMap = new HashMap<String, String>();
		_tempMap.put("label", "ZC");
		_tempMap.put("text", "综采");
		_tempMap.put("parentTypes", "0_综采");
		_tempMap.put("leaf", "1");
		_list.add(_tempMap);
		
//		_tempMap = new HashMap<String, String>();
//		_tempMap.put("label", "LC");
//		_tempMap.put("text", "连采");
//		_tempMap.put("parentTypes", "0_连采");
//		_tempMap.put("leaf", "1");
//		_list.add(_tempMap);
//		
//		_tempMap = new HashMap<String, String>();
//		_tempMap.put("label", "JC");
//		_tempMap.put("text", "机采");
//		_tempMap.put("parentTypes", "0_机采");
//		_tempMap.put("leaf", "1");
//		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", "PC");
		_tempMap.put("text", "炮采");
		_tempMap.put("parentTypes", "0_炮采");
		_tempMap.put("leaf", "1");
		_list.add(_tempMap);
		
		return _list;
	}
	
	/**
	 * 掘进的二级分类
	 * <p>Function: CMList</p>
	 * <p>Description: </p>
	 * <p>return label:List<Map<String,String>></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-9-1上午08:15:23 zk
	 * </p>
	 *
	 */
	private List<Map<String, String>> JJList() {
		List<Map<String, String>> _list = new ArrayList<Map<String, String>>();
		
		Map<String, String> _tempMap = new HashMap<String, String>();
		_tempMap.put("label", "KT");
		_tempMap.put("text", "开拓");
		_tempMap.put("parentTypes", "1_开拓");
		_tempMap.put("leaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", "HC");
		_tempMap.put("text", "回采");
		_tempMap.put("parentTypes", "1_回采");
		_tempMap.put("leaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", "ZB");
		_tempMap.put("text", "准备");
		_tempMap.put("parentTypes", "1_准备");
		_tempMap.put("leaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", "YS");
		_tempMap.put("text", "延伸");
		_tempMap.put("parentTypes", "1_延伸");
		_tempMap.put("leaf", "1");
		_list.add(_tempMap);
		
		return _list;
	}
	
	/**
	 * 通防的二级分类
	 * <p>Function: CMList</p>
	 * <p>Description: </p>
	 * <p>return label:List<Map<String,String>></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-9-1上午08:15:23 zk
	 * </p>
	 *
	 */
	private List<Map<String, String>> TFList() {
		List<Map<String, String>> _list = new ArrayList<Map<String, String>>();
		
		Map<String, String> _tempMap = new HashMap<String, String>();
		_tempMap.put("label", "DZ");
		_tempMap.put("text", "打钻");
		_tempMap.put("parentTypes", "2_打钻");
		_tempMap.put("leaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", "CC");
		_tempMap.put("text", "抽采");
		_tempMap.put("parentTypes", "2_抽采");
		_tempMap.put("leaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", "GLAZ");
		_tempMap.put("text", "管路安装");
		_tempMap.put("parentTypes", "2_管路安装");
		_tempMap.put("leaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", "SLCK");
		_tempMap.put("text", "水力冲孔");
		_tempMap.put("parentTypes", "2_水力冲孔");
		_tempMap.put("leaf", "1");
		_list.add(_tempMap);
		
		return _list;
	}
	
	
	/**
	 * 其他的二级分类
	 * <p>Function: CMList</p>
	 * <p>Description: </p>
	 * <p>return label:List<Map<String,String>></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-9-1上午08:15:23 zk
	 * </p>
	 *
	 */
	private List<Map<String, String>> QTList() {
		List<Map<String, String>> _list = new ArrayList<Map<String, String>>();
		
		Map<String, String> _tempMap = new HashMap<String, String>();
		_tempMap.put("label", "XX");
		_tempMap.put("text", "巷修");
		_tempMap.put("parentTypes", "3_巷修");
		_tempMap.put("leaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", "AC");
		_tempMap.put("text", "按拆");
		_tempMap.put("parentTypes", "3_按拆");
		_tempMap.put("leaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", "LX");
		_tempMap.put("text", "零星");
		_tempMap.put("parentTypes", "3_零星");
		_tempMap.put("leaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", "PJ");
		_tempMap.put("text", "喷浆");
		_tempMap.put("parentTypes", "3_喷浆");
		_tempMap.put("leaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", "WD");
		_tempMap.put("text", "卧底");
		_tempMap.put("parentTypes", "3_卧底");
		_tempMap.put("leaf", "1");
		_list.add(_tempMap);
		
		_tempMap = new HashMap<String, String>();
		_tempMap.put("label", "QTQT");
		_tempMap.put("text", "其他");
		_tempMap.put("parentTypes", "3_其他");
		_tempMap.put("leaf", "1");
		_list.add(_tempMap);
		
		return _list;
	}
	
	/**
	 * 列定义
	 * <p>Function: initMetaData</p>
	 * <p>Description: </p>
	 * <p>return label: ServiceZMCS80</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-9-1上午06:53:26 zk
	 * </p>
	 *
	 */
	@Override
	public EiBlockMeta initMetaData() {
		EiBlockMeta eiMetadata = new EiBlockMeta();

		EiColumn eiColumn = new EiColumn("label");
		eiColumn.setDescName("label");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		eiColumn = new EiColumn("text");
		eiColumn.setDescName("text");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		eiColumn = new EiColumn("parentTypes");
		eiColumn.setDescName("parentTypes");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		eiColumn = new EiColumn("childTypes");
		eiColumn.setDescName("小类");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		eiColumn = new EiColumn("imagePath");
		eiColumn.setDescName("imagePath");
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		eiColumn = new EiColumn("leaf");
		eiColumn.setDescName("leaf");
		eiColumn.setType(EiConstant.COLUMN_TYPE_NUMBER);
		eiColumn.setNullable(false);
		eiColumn.setPrimaryKey(false);
		eiMetadata.addMeta(eiColumn);
		
		return eiMetadata;
	}
	
	public String getTypeByNode(String node)
	{
		String type ="";
		if(node.equals("CM")|| node.equals("ZC")|| node.equals("LC")|| node.equals("LC"))
		{
			type = "0";
		}else if(node.equals("JJ")|| node.equals("KT")|| node.equals("HC")|| node.equals("WSZL"))
		{
			type = "1";
		}else if(node.equals("TF")|| node.equals("DZ")|| node.equals("CC")|| node.equals("GLAZ")|| node.equals("SLCK"))
		{
			type = "2";
		}else
		{
			type = "3";
		}
		return type;
	}
}
